<?php 
class Fields {
	
	private $fieldsList = array();
	
	function __construct() {
	}
	
	function addFiels($name, $type, $value){
		$this->fieldsList[$name] = array('type' => $type, 'value' => $value, 'valid' => false);
		
		//call validation method
		$method = $type.'Validation';
		$this->fieldsList[$name]["valid"] = $this->$method($value);
	}
	
	function isValid(){
		$return = true;
	
		if (count($this->fieldsList) == 0) {
			$return = false;
		}
	
		foreach ($this->fieldsList as $field) {
			if ($field["valid"] === false) {
				$return = false;
			}
		}
	
		return $return;
	}
	
	private function slugValidation($val) {
		$return = false;
		
		if (strlen($val) > 0) {
			#convert case to lower
			$val = strtolower($val);
			
			#change special characters into space
			$val = preg_replace('/[^a-zA-Z0-9-]/i',' ', $val);
			
			if (!is_int(strpos($val, " "))){
				$return = true;
			}
		}
		return $return;
	}
	
	private function stringValidation($val) {
		$return = false;
		$val = trim($val);
		
		if (strlen($val) > 0){
			$return = true;
		}
		
		return $return;
	}
	
	private function emailValidation($val) {
		$return = false;
		$val = trim($val);
	
		//if (filter_var($val, FILTER_VALIDATE_EMAIL) > 0){
			//$return = true;
		//}
	
		$expression = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/";
		if (preg_match($expression, $val)) {
			$return = true;
		}
		
		return $return;
	}
	
	
}
?>